<?php
class RegisterController extends  Controller{

	
	public function index(){
        $smaryt = $this->getSmarty();
        $this->smarty->assign ( 'pagesets', $this->headerDatas() );
        //如果不是post方式的提交，直接转向
        if(!CommonBase::isPost()){
            $this->smarty->display("register.tpl");
            return;
        }
        $email = $_POST ["email"];
        if(empty($email)){
            $this->smarty->assign("errortip",$this->userExsist('必须填写Email'));

            $this->smarty->display("register.tpl");
        }
        require_once SERVICE . DS . 'admin' . DS . 'UsersService.class.php';
        $userService = new UsersService( $this->getDB());

        $user = $userService->getEmailByName($email);

        if(!empty($user->email)){
            $this->smarty->assign("errortip",$this->userExsist('此用户已经存在，不能重复注册'));
            $this->smarty->assign("email",$email);
            $this->smarty->assign("password",$_POST["password"]);
            $this->smarty->display("register.tpl");
            return ;
        }

        $user = array(
            'login_type' => 0,
            'password' => md5($_POST["password"] ),
            'email' => $_POST["email"]
        );
        $userService->addUser($user);

        require_once COMMON.DS.'SendMailUtil.class.php';
        SendMailUtil::sendmail("欢迎注册Ibo123",$email.",注册成功",$email);
        $this->smarty->assign("errortip",$this->userSuccess('注册成功'));
        $this->smarty->display("register.tpl");
	}

public function handreg(){
    $this->getSmarty();
}
public function userExsist($msg){
    return "<div class='alert alert-error'>$msg</div>";
}
public function userSuccess($msg){
    return "<div class='alert alert-success'>$msg</div>";
}
public function headerDatas(){
        require_once COMMON . DS  . 'Constant.class.php';
        $js = array(WEBSITE_URL."public/assets/js/jquery.validationEngine-zh.js",WEBSITE_URL."public/assets/js/jquery.validationEngine.js");
        $css = array(WEBSITE_URL."public/assets/css/validationEngine.jquery.css");
        $pagesets = array("seo"=>Constant::$seoarray,"js"=>$js,"css"=>$css,"nav"=>Constant::getNav());
        return $pagesets;
}

}